using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using System.Windows.Forms;
using System.Reflection;

namespace CSDesktopUsiXMLRenderer
{
    abstract class UsiXMLElementRenderer
    {
        public abstract String getValidElementName();
        public abstract Control processRenderization(XmlNode element);
        public abstract UsiXMLElementRenderer getNextRenderer();

        protected UsiXMLInterfaceRenderer usiXMLInterfaceRenderer = null;

        public UsiXMLElementRenderer(){
        }

        public void setInterfaceRenderer(UsiXMLInterfaceRenderer usiXMLInterfaceRenderer) {
		    this.usiXMLInterfaceRenderer = usiXMLInterfaceRenderer;
	    }

        public Control renderElement(XmlNode element)
        {
    	
		    if (element.Name == this.getValidElementName()){
			    return this.processRenderization(element);
		    }else{
			    return this.getNextRenderer().renderElement(element);
		    }
    		
	    }

        protected void insertContent(XmlNode node, Control component)
        {

            ResourceRetriever resourceRetriever = this.usiXMLInterfaceRenderer.getResourceRetriever();
            String resourceContent = resourceRetriever.getStringResourceContent(node);

            Type componentType = component.GetType();
            MethodInfo method = componentType.GetMethod("set_Text");
            method.Invoke(component, new object[] { resourceContent });
                        

        }
    }
}
